package com.ming.yygh.hosp.controller.api;

import com.ming.yygh.common.result.Result;
import com.ming.yygh.hosp.service.DepartmentService;
import com.ming.yygh.hosp.service.HospitalService;
import com.ming.yygh.hosp.service.HospitalSetService;
import com.ming.yygh.hosp.service.ScheduleService;
import com.ming.yygh.model.hosp.Hospital;
import com.ming.yygh.model.hosp.Schedule;
import com.ming.yygh.vo.hosp.DepartmentVo;
import com.ming.yygh.vo.hosp.HospitalQueryVo;
import com.ming.yygh.vo.hosp.ScheduleOrderVo;
import com.ming.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Light
 * @date 2021/12/14 15:01
 */
@Api(tags = "用户端相关接口")
@RestController
@RequestMapping("api/hosp/hospital")
public class HospApiController {

    @Resource
    private HospitalService hospitalService;

    @Resource
    private DepartmentService departmentService;

    @Resource
    private ScheduleService scheduleService;

    @Resource
    private HospitalSetService hospitalSetService;

    @ApiOperation(value = "查询医院列表")
    @GetMapping("/findHospitalList/{page}/{limit}")
    public Result<Page<Hospital>> findHospitalList(@PathVariable(value = "page") Integer page,
                                                   @PathVariable(value = "limit") Integer limit,
                                                   HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitalPage = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitalPage);
    }

    @ApiOperation(value = "根据医院名称查询")
    @GetMapping("/findByHosName/{hosname}")
    public Result findByHosName(@PathVariable(value = "hosname") String hosname) {
        List<Hospital> hospitalList = hospitalService.findByHosName(hosname);
        return Result.ok(hospitalList);
    }

    @ApiOperation(value = "根据医院编号获取科室信息")
    @GetMapping("/department/{hoscode}")
    public Result<List<DepartmentVo>> departmentInfo(@PathVariable(value = "hoscode") String hoscode) {
        return Result.ok(departmentService.findDeptTree(hoscode));
    }

    @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
    @GetMapping("/findHospDetail/{hoscode}")
    public Result<Map<String, Object>> findHospDetail(@PathVariable(value = "hoscode") String hoscode) {
        return Result.ok(hospitalService.findHospDetail(hoscode));
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result<List<Schedule>> findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("/getSchedule/{scheduleId}")
    public Result<Schedule> getSchedule(@PathVariable(value = "scheduleId") String scheduleId) {
        Schedule schedule = scheduleService.getScheduleById(scheduleId);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    public Result<ScheduleOrderVo> getScheduleOrderVo(@PathVariable(value = "scheduleId") String scheduleId) {
        ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
        return Result.ok(scheduleOrderVo);
    }

    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public Result<SignInfoVo> getSignInfoVo(@PathVariable(value = "hoscode") String hoscode) {
        SignInfoVo signInfoVo = hospitalSetService.getSignInfoVo(hoscode);
        return Result.ok(signInfoVo);
    }

}

